
//---------------file
Apps.file = function(obj){	return Apps.file.anew(obj);}
Apps.file.anew = function(obj){this.obj=obj;	return this;}
//--进入指定路径
Apps.file.path_go = function(){
	var dir = jQuery(".Adev ._nav ._dir").val();
	var url = jQuery("#Aurl_Aactr").val();
	window.location = url+'?dir='+dir;
	return false;
}
//--添加
Apps.file.add_show = function(title,html,css){
	var obj=Object();
	obj.id='ajax_dev';
	obj["class"]='acan_win dis_none';
	if(css){
		if(!css.height) css.height='150px';
		obj.css=css;
	}else{
		obj.css={height:'150px'};
	}
	obj._close={onclick:'Acan.close(\''+obj.id+'\')','class':'-close'};//关闭按钮
	Acan.base.win(obj,title,html);
	Acan.ajax_bg();
}
Apps.file.add = function(type){
	var Ahtml = Acan.html();
	var url = jQuery("#Aurl_Amodr").val()+'-add';
	var str_sub = '新增';
	if(type=='dir'){
		var html = Ahtml.tag('form',{onsubmit:'Apps.file.save(\'dir\',\''+url+'\');return false;',method:'post'},
			Ahtml.tag('p',{},'文件夹名： '+Ahtml.tag('input',{type:"text",name:"newname"}))
			+Ahtml.tag('p',{},Ahtml.tag('input',{type:"submit",name:"submit",value:str_sub}))
		);
		var title = '新建文件夹';
	}else if(type='file'){
		var html = Ahtml.tag('form',{onsubmit:'Apps.file.save(\'file\',\''+url+'\');return false;',method:'post'},
			Ahtml.tag('p',{},'文件名： '+Ahtml.tag('input',{type:"text",name:"newname"}))
			+Ahtml.tag('p',{},'内容： '+Ahtml.tag('input',{type:"text",name:"note"}))
			+Ahtml.tag('p',{},Ahtml.tag('input',{type:"submit",name:"submit",value:str_sub}))
		);
		var title = '新建文件';
	}
	this.add_show(title,html);
}
Apps.file.rename = function(type,names){
	var Ahtml = Acan.html();
	var url = jQuery("#Aurl_Amodr").val()+'-rename';
	var str_sub = '重命名';
	if(type=='dir'){
		var html = Ahtml.tag('form',{onsubmit:'Apps.file.save(\'dir\',\''+url+'\');return false;',method:'post'},
			Ahtml.tag('p',{},'原文件名： '+Ahtml.tag('input',{type:"text",name:"name",value:names}))
			+Ahtml.tag('p',{},'新文件名： '+Ahtml.tag('input',{type:"text",name:"newname",value:names}))
			+Ahtml.tag('p',{},Ahtml.tag('input',{type:"submit",name:"submit",value:str_sub}))
		);
		var title = '重命名文件夹';
	}else if(type='file'){
		var html = Ahtml.tag('form',{onsubmit:'Apps.file.save(\'file\',\''+url+'\');return false;',method:'post'},
			Ahtml.tag('p',{},'文件名： '+Ahtml.tag('input',{type:"text",name:"name",value:names}))
			+Ahtml.tag('p',{},'新文件名： '+Ahtml.tag('input',{type:"text",name:"newname",value:names}))
			+Ahtml.tag('p',{},Ahtml.tag('input',{type:"submit",name:"submit",value:str_sub}))
		);
		var title = '重命名文件';
	}
	this.add_show(title,html);
}
Apps.file.save = function(type,url,fun){
	Acan.close('ajax_dev');
	var params=jQuery('#ajax_dev input').serialize();
	var path = jQuery("#Adev_path").val();
	jQuery.ajax({
		type: "POST",
		url: url,
		data: params+"&type="+type+"&path="+path,
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			if(fun){
				Acan.alert();
				fun(data);
			}else{
				Acan.alert(decodeURI(data),1500);
			}
			Apps.file.ajax_list(type);
		}
	})
}
Apps.file.del = function(type,val){
	var ttt = '';
	if(type=='dir'){ttt = '夹 ';}
	if(!confirm('确实要删除文件'+ttt+val+' 吗?')){return false;}
	var path = jQuery("#Adev_path").val();
	var url = jQuery("#Aurl_Amodr").val()+'-del-'+type+'?path='+path+val;
	jQuery.ajax({
		type: "POST",
		url: url,
		data: '',
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			Acan.alert(decodeURI(data),1000);
			Apps.file.ajax_list(type);
		}
	})
}
Apps.file.ajax_list = function(type){
	var path = jQuery("#Adev_path").val();
	var url = jQuery("#Aurl_Amodr").val()+'-list-list_'+type+'?dir='+path;
	var obj = jQuery(".Adev ._"+type);
	jQuery.ajax({
		type: "GET",
		url: url,
		data: '',
		beforeSend: function(){obj.html('正在刷新中...');},
		success: function(data){
			obj.html(decodeURI(data));
		}
	})
}
Apps.file.upfile = function(path){
	var url = jQuery("#Aurl_Amodr").val()+'-upfile?path='+path;
	var html = Ahtml.tag('iframe',{src:url,name:"a_upfile",frameborder:"0",height:'100%',width:'100%'})
	this.add_show('上传文件',html,{height:'200px',width:'480px','text-align':'left'});
}
Apps.file.edit = function(title,str){
	var url = jQuery("._history ._edit_list").val();
	Atab.task_new(title,url,str);
}
//--压缩文件
Apps.file.zip = function(){
	var url = jQuery("#Aurl_Amodr").val()+'-zip';
	var chkd = jQuery('._dir input[name="_dir[]"]:checked');
	var chkf = jQuery('._file input[name="_file[]"]:checked');
	var tmpname='';
	var tmpdir = "";
	var tmpfile = "";
	if(chkd.length>0){//文件夹
		tmpname = chkd[0].value;
		for (var i=0; i < chkd.length; i++) {
			tmpdir += Ahtml.tag('input',{type:"checkbox",name:"zip[]",checked:"checked",value:chkd[i].value})+chkd[i].value+'<br>';
		}
		tmpdir = Ahtml.dt('选择的文件夹：')+Ahtml.dd(tmpdir);
	}
	if(chkf.length>0){//文件
		if(tmpname==''){tmpname = chkf[0].value;}
		for (var i=0; i < chkf.length; i++) {
			tmpfile += Ahtml.tag('input',{type:"checkbox",name:"zip[]",checked:"checked",value:chkf[i].value})+chkf[i].value+'<br>';
		}
		tmpfile = Ahtml.dt('选择的文件：')+Ahtml.dd(tmpfile)
	}
	if(chkf.length==0 && chkd.length==0){
		Acan.alert("请先选择文件或文件夹!",1000);
		return;
	}
	var tmp7 = '';
	var ziptype = ['zip','7z','tar'];
	for (var i=0; i < ziptype.length; i++) {
		if(i==0){
			tmp7 += Ahtml.tag('input',{type:"radio",name:"ziptype",checked:"checked",value:ziptype[i]})+ziptype[i];
		}else{
			tmp7 += Ahtml.tag('input',{type:"radio",name:"ziptype",value:ziptype[i]})+ziptype[i];
		}
	}
	var html = Ahtml.tag('form',{onsubmit:'Apps.file.save(\'file\',\''+url+'\',Apps.file.zipData);return false;',method:'post'},
		Ahtml.dl({'class':'-dl'},
			Ahtml.dt('压缩文件名:')+Ahtml.dd(Ahtml.tag('input',{type:"text",name:"name",value:tmpname})+Ahtml.tag('input',{type:"submit",name:"submit",value:"压缩"}))
			+Ahtml.dt('压缩格式:')+Ahtml.dd(tmp7)
			+tmpdir+tmpfile
		)
	);
	this.add_show('添加到压缩文件',html,{height:'400px',width:'480px','text-align':'left'});
	return;
}
//--压缩结果
Apps.file.zipData = function(data){
	Apps.file.add_show('压缩信息',data,{height:'400px',width:'480px'});
}
//--解压文件
Apps.file.unzip = function(filename){
	var url = jQuery("#Aurl_Amodr").val()+'-unzip';
	var chkf = jQuery('._file input[name="_file[]"]:checked');
	var path = jQuery("#Adev_path").val();
	if(filename != null){
	}else if(chkf.length==1){
		filename = chkf[0].value;
		var frr = filename.split('.');
		//判断压缩文件格式是否正确
		var ziptype = ['zip','7z','tar'];
		if(frr.length<2 || Acan.base.in_array(frr[frr.length-1],ziptype)==false){
			Acan.alert("该文件不是(zip,7z,tar)压缩文件!请重新选择",2000);return;
		}
	}else if(chkf.length>1){
		Acan.alert("请不要选择多个文件!",1000);
		return;
	}else{
		Acan.alert("请先选择一个要压缩包文件!",1000);
		return;
	}
	var html = Ahtml.tag('form',{onsubmit:'Apps.file.save(\'file\',\''+url+'\',Apps.file.unzipData);return false;',method:'post'},
		Ahtml.dl({'class':'-dl'},
			Ahtml.dt('已选文件:')+Ahtml.dd(filename+Ahtml.tag('input',{type:"hidden",name:"name",value:filename}))
			+Ahtml.dt('解压路径')+Ahtml.dd(Ahtml.tag('input',{type:"text",name:"unpath",value:path}))
			+Ahtml.dt('解压')+Ahtml.dd(Ahtml.tag('input',{type:"submit",name:"submit",value:"解压"}))
		)
	);
	this.add_show('解压文件',html);
	return;
}
//--解压结果
Apps.file.unzipData = function(data){
	Apps.file.add_show('解压结果',data,{height:'400px',width:'480px','text-align':'left'});
}

Apps.file.chks = function(str){
	if(str=='all'){
		jQuery('input[type="checkbox"]').attr("checked","checked");
	}else if(str=='dir'){
		jQuery('._dir input[type="checkbox"]').attr("checked","checked");
	}else if(str=='file'){
		jQuery('._file input[type="checkbox"]').attr("checked","checked");
	}else if(str=='none'){
		jQuery('input[type="checkbox"]').removeAttr("checked");
	}
}
Apps.file.chk = function(obj){
	obj = jQuery("#"+obj.id);
	var chk = obj.find('input[type="checkbox"]');
	if(chk.attr('checked')=='checked'){
		chk.removeAttr('checked');
	}else{
		chk.attr('checked','checked');
	}
}
